window.onload = function() {
    layui.use(['jquery', 'layer'], function() {
        var $ = layui.jquery,
            layer = layui.layer;

        //完成
        $('.update-complete').on('click', function() {
            // ShowCompleteBox();
            Utils.layer.open({
                type: 1,
                title: '通过',
                area: '300px',
                content: openHtml('请输入处理信息'),
                btn: ['确认', '取消'],
                btn1: function() {
                    var info = $('.b-text').val();
                    if (info == '') {
                        Utils.layer.msg('请输入处理信息');
                        return
                    } else {
                        var id = $('.update-complete').attr('dataid');
                        var result = $(".b-text").val();
                        $.ajax({
                            url: '/complaint/update-complete',
                            type: 'post',
                            data: {
                                id: id,
                                result: result,
                            },
                            dataType: 'json',
                            success: function(data) {
                                Utils.layer.msg(data.count);
                                setTimeout(function() {
                                    location.href = "/complaint/index";
                                }, 1200)
                            }
                        })
                    }
                },
                btn2: function() {

                }
            })

        });

        // 未通过/通过
        $('.disagree,.agree').on('click', function() {
            var id = $(this).attr('id');
            var status = $(this).attr('status');
            Utils.layer.open({
                type: 1,
                title: '未通过/通过',
                area: '300px',
                content: openHtml('请输入处理信息'),
                btn: ['确认', '取消'],
                btn1: function() {
                    var info = $('.b-text').val();
                    if (info == '') {
                        Utils.layer.msg('请输入处理信息');
                        return
                    } else {
                        $.post('/complaint/change-status', { id: id, status: status, dismissal: info }, function(data) {
                            Utils.layer.msg(data.count);
                            setTimeout(function() {
                                location.reload();
                            }, 1200);
                        })
                    }
                },
                btn2: function() {

                }
            })
        });


        function openHtml(title) {
            return "<div class='b-div' style='width:90%; margin:15px auto 0;'><p class='b-p' style='font-size:15px; color:#999; margin-bottom:10px;'>" + title + "</p><input type='text' class='layui-input b-text'><div class='b-btn'></div></div>"
        }
    })
}